package com.mdd.admin.controller.yylq;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.yylq.ITAppDicService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.validate.yylq.TAppDicCreateValidate;
import com.mdd.admin.validate.yylq.TAppDicSearchValidate;
import com.mdd.admin.validate.yylq.TAppDicUpdateValidate;
import com.mdd.admin.vo.yylq.TAppDicDetailVo;
import com.mdd.admin.vo.yylq.TAppDicListedVo;
import com.mdd.common.aop.NotLogin;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.entity.yangyangLeadingEnterprise.common.JsonReturn;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/adminapi/yylq/dic")
@Api(tags = "羊羊领企---字典管理")
public class TAppDicController {

    @Resource
    ITAppDicService iTAppDicService;

    @GetMapping("/list")
    @ApiOperation(value="字典列表")
    public AjaxResult<PageResult<TAppDicListedVo>> list(@Validated PageValidate pageValidate,
                                                        @Validated TAppDicSearchValidate searchValidate) {
        PageResult<TAppDicListedVo> list = iTAppDicService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="字典详情")
    public AjaxResult<TAppDicDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        TAppDicDetailVo detail = iTAppDicService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "字典新增")
    @PostMapping("/add")
    @ApiOperation(value="字典新增")
    public AjaxResult<Object> add(@Validated @RequestBody TAppDicCreateValidate createValidate) {
        iTAppDicService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "字典编辑")
    @PostMapping("/edit")
    @ApiOperation(value="字典编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody TAppDicUpdateValidate updateValidate) {
        iTAppDicService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "字典删除")
    @PostMapping("/del")
    @ApiOperation(value="字典删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iTAppDicService.del(idValidate.getId());
        return AjaxResult.success();
    }

    @NotLogin
    @PostMapping("/test001")
    @ApiOperation(value="")
    public String test001(HttpServletRequest request) {
        String token = request.getHeader("token");
        String userId = request.getHeader("userId");

        return JsonReturn.success().put("token",token).put("userId",userId).toJsonStr();
    }

}
